﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Computer_Manager.DTO;

namespace Computer_Manager.DAL
{
    class DAL_company
    {
        DbProvider db = new DbProvider();
        SqlCommand cmd;

        public void company_insert(DTO_company dt)
        {
            db.Open();
            cmd = new SqlCommand("company_Insert", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@company_id", SqlDbType.Int).Value = dt.company_id;
            cmd.Parameters.Add("@company", SqlDbType.NVarChar).Value = dt.company;
            cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = dt.address;
            cmd.Parameters.Add("@tel", SqlDbType.VarChar).Value = dt.tel;
            cmd.Parameters.Add("@fax", SqlDbType.VarChar).Value = dt.fax;
            cmd.Parameters.Add("@webSite", SqlDbType.VarChar).Value = dt.webSite;
            cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = dt.email;
            cmd.Parameters.Add("@tax", SqlDbType.VarChar).Value = dt.tax;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void company_Update(DTO_company dt)
        {
            db.Open();
            cmd = new SqlCommand("company_Update", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@company_id", SqlDbType.Int).Value = dt.company_id;
            cmd.Parameters.Add("@company", SqlDbType.NVarChar).Value = dt.company;
            cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = dt.address;
            cmd.Parameters.Add("@tel", SqlDbType.VarChar).Value = dt.tel;
            cmd.Parameters.Add("@fax", SqlDbType.VarChar).Value = dt.fax;
            cmd.Parameters.Add("@webSite", SqlDbType.VarChar).Value = dt.webSite;
            cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = dt.email;
            cmd.Parameters.Add("@tax", SqlDbType.VarChar).Value = dt.tax;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void company_Delete(DTO_company dt)
        {
            db.Open();
            cmd = new SqlCommand("company_Delete", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@company_id", SqlDbType.Int).Value = dt.company_id;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            db.getConn().Close();
        }
        public DataTable GetAll()
        {
            SqlDataAdapter adapter = new SqlDataAdapter("company_SelectAll", db.getConn());
            DataTable table = new DataTable();
            adapter.Fill(table);
            adapter.Dispose();
            return table;
        }
        public DataTable GetByID(DTO_company dt)
        {
            cmd = new SqlCommand("company_GetByID", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@company_id", SqlDbType.Int).Value = dt.company_id;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }

    }
}
